/****************************************************************
*   Used for alarm's second module or minute module
****************************************************************/

module alarmCnt60 (
  input   wire        rstn   ,
  input   wire        clk    ,
  input   wire        set_alarm,
  input   wire        set    ,

  output  reg  [3:0]  upper  ,      // the ten
  output  reg  [3:0]  low           // the one
);

// low
always @(posedge clk or negedge rstn) begin
  if(~rstn)
    low  	<=  4'h0;
  else if(set_alarm) begin
    if(low == 4'h9 && set)
      low 	<=  4'h0;
    else if(set)
      low 	<=  low + 1'b1;
  end
end

// upper
always @(posedge clk or negedge rstn) begin
  if(~rstn) begin
    upper   <=  4'h0;
  end
  else if(set_alarm) begin
    if(low == 4'h9 && upper == 4'h5 && set)
      upper   <=  4'h0;
    else if(low == 4'h9 && set)
      upper   <=  upper + 1'b1;
  end
end
    
endmodule
